package tp.badugi.net;

import static org.junit.Assert.*;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;

public class GameStatusTest {

	@Test
	public void testGameStatusJSONConversion() throws JSONException {
		GameStatus gameStatus = new GameStatus();
		
		gameStatus.myPlayerNumber = 3;
		gameStatus.myChipCount = 1000;
		gameStatus.myCards = new String[] {"AS","2C","3H","4D"};
		gameStatus.numberOfPlayers = 1;
		gameStatus.playerStatuses = new boolean[] {true, false};
		gameStatus.playerNames = new String[] {"P1","P2","P3"};
		gameStatus.playerChipCounts = new long[] {1L, 2L, 3L, 4L, 5L};
		gameStatus.playerPotContributions = new long [] {1L, 2L, 3L, 4L, 5L, 6L};
		gameStatus.playerWithDealerButton = 43;
		gameStatus.smallBlind = 234L;
		gameStatus.bigBlind = 232134L;
		gameStatus.bettingRound = 10;
		gameStatus.playerInAction = 9;
		gameStatus.betAmount = 23234112L;
		gameStatus.potSize = 1010101010101L;
		gameStatus.tableName = "Table";
		
		String jsonGameStatus = gameStatus.toJSONObject().toString();
		GameStatus gameStatus2 = GameStatus.fromJSONObject(new JSONObject(jsonGameStatus));
		
		assertEquals(gameStatus.myPlayerNumber, gameStatus2.myPlayerNumber);
		assertEquals(gameStatus.myChipCount, gameStatus2.myChipCount);
		assertArrayEquals(gameStatus.myCards, gameStatus2.myCards);
		assertEquals(gameStatus.numberOfPlayers, gameStatus2.numberOfPlayers);
		assertEquals(gameStatus.playerStatuses[1], gameStatus2.playerStatuses[1]);
		assertArrayEquals(gameStatus.playerNames, gameStatus2.playerNames);
		assertArrayEquals(gameStatus.playerChipCounts, gameStatus2.playerChipCounts);
		assertArrayEquals(gameStatus.playerPotContributions, gameStatus2.playerPotContributions);
		assertEquals(gameStatus.playerWithDealerButton, gameStatus2.playerWithDealerButton);
		assertEquals(gameStatus.smallBlind, gameStatus2.smallBlind);
		assertEquals(gameStatus.bigBlind, gameStatus2.bigBlind);
		assertEquals(gameStatus.bettingRound, gameStatus2.bettingRound);
		assertEquals(gameStatus.playerInAction, gameStatus2.playerInAction);
		assertEquals(gameStatus.betAmount, gameStatus2.betAmount);
		assertEquals(gameStatus.potSize, gameStatus2.potSize);
		assertEquals(gameStatus.tableName, gameStatus2.tableName);
	}

}
